from types import MethodType

class Person(object):
    # 限制为这个类动态添加方法
    __slots__ = ("name", "age", "speak")
    pass

per = Person()
per.name = "zss"
print(per.name)

def say(self):
    print("my name is: " + self.name)

per.speak = MethodType(say, per)
per.speak()

# __slots__里面没有定义这个属性，所有会报错
# per.fly = True

